#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
class Solution {
public:
    string reverseWords(string s) {
        string tmp;
        vector<string> vec;
        int slow = 0,fast;
        while(slow < s.size()){
            if(s[slow] == ' '){
                slow ++;
                continue;
            }
            tmp += s[slow];
            fast = slow + 1;
            while(fast < s.size() && s[fast]!=' '){
                tmp += s[fast];
                fast++;
            }
            vec.push_back(tmp);
            tmp = "";
            slow = fast;
        }
        tmp = "";
        for(int i=vec.size()-1;i>=1;i--){
            tmp+=vec[i]+' ';
        }
        tmp +=vec[0];
        return tmp;
    }
};

int main()
{
    Solution solution;
    string s = "the sky is blue";

    cout<<solution.reverseWords(s);
    return 0;
}